package com.zhao.mianshi

import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

/**
 * Description: <br/>
 * Copyright (c) ，2020 ， 赵 <br/>
 * This program is protected by copyright laws. <br/>
 * Date： 2020/11/16 15:15
 * 需求:求出每个栏目的被观看次数及累计观看时长
 * uid channl min
 * 1	1	23
 * 2	1	12
 * 3	1	12
 * 4	1	32
 * 5	1	342
 * 6	2	13
 * 7	2	34
 * 8	2	13
 * 9	2	134
 *
 * @author 柒柒
 * @version : 1.0
 */

object test2 {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setAppName(this.getClass.getName)
      .setMaster("local[*]")


    val spark: SparkSession = SparkSession.builder().config(conf)
      .enableHiveSupport() //默认不支持外部hive,这里需要调用方法
      .getOrCreate()
    spark.sql("use mianshi")

    spark.sql(
      """
        |select channl,count(1),sum(min) sum_min
        |    from mianshi2
        |group by channl
        |""".stripMargin).show()
  }
}
